import { createSlice } from "@reduxjs/toolkit";
import { getTableData } from "@/service/api.js";

export const counterSlice = createSlice({
  name: "tableStore",
  initialState: {
    title: "我是table状态管理",
    tableData: [],
  },
  reducers: {
    increase(state) {
      state.tableData.push({
        name: "肖明华",
        age: 20,
      });
    },
  },
  extraReducers: (builder) => {
    builder.addCase(getTableData.fulfilled, (state, action) => {
      const res = action.payload;
      if (res && res?.code === 200) {
        state.tableData = res.data;
      }
    });
  },
});

export const { increase } = counterSlice.actions;
export default counterSlice.reducer;
